package com.cs307.redcross.client;

import java.io.Serializable;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;

public class TemplatesSubheader extends Subheader implements Serializable {
	private static final long serialVersionUID = 4223721994412995286L;
	protected ToggleButton selectedButton;
	
	public TemplatesSubheader() {
		
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		initWidget(horizontalPanel);
		horizontalPanel.setSize("239px", "15px");
		
		FlexTable flexTable = new FlexTable();
		horizontalPanel.add(flexTable);
		flexTable.setWidth("367px");
		
		ToggleButton eventTemplatesButton = new ToggleButton("Event Templates");
		eventTemplatesButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// show the new content in ContentPanel
				ContentPanel.getInstance().setContent(new TemplatesEventContent());
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		horizontalPanel.add(eventTemplatesButton);
		eventTemplatesButton.setSize("106px", "18px");
		
		ToggleButton reminderTemplatesButton = new ToggleButton("Reminder Templates");
		reminderTemplatesButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
				// show the new content in ContentPanel
				ContentPanel.getInstance().setContent(new TemplatesReminderContent());
				
				// untoggle the last selected button
				if (selectedButton != null)
					selectedButton.setDown(false);
				selectedButton = (ToggleButton)event.getSource();
			}
		});
		horizontalPanel.add(reminderTemplatesButton);
		reminderTemplatesButton.setSize("143px", "18px");
		
		// set view to be the default view loaded
		eventTemplatesButton.setDown(true);
		selectedButton = eventTemplatesButton;
	}

}
